﻿using Microsoft.AspNetCore.Http;

namespace Luka;

/// <summary>
/// 自定义异常类
/// </summary>
[NotScanned]
public sealed class FriendlyException : Exception
{
    /// <summary>
    /// 响应代码
    /// </summary>
    public int EorrorCode { get; set; }

    /// <summary>
    /// 消息
    /// </summary>
    public string? ErrorMessage { get; set; }

    /// <summary>
    /// 是否是数据验证异常
    /// </summary>
    public bool ValidationException { get; set; } = false;

    /// <summary>
    /// 构造函数
    /// </summary>
    public FriendlyException() : base()
    {
        EorrorCode = StatusCodes.Status400BadRequest;
    }

    /// <summary>
    /// 构造函数
    /// </summary>
    public FriendlyException(string message, int errorCode = StatusCodes.Status400BadRequest) : base(message)
    {
        ErrorMessage = message;
        EorrorCode = errorCode;
    }
}